package dr.incomeapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import dr.incomeapp.bean.IncomeBean;
import dr.incomeapp.controller.IncomeManagerController;
import dr.incomeapp.dao.FactoryDao;
import dr.incomeapp.dao.IncomeDao;


public class MainActivity extends Activity implements OnClickListener {
	
	
	protected Button btnList;
	protected Button btnTable;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		Application.CreateInstance(this.getApplicationContext());
		/*
		IncomeDao dao = FactoryDao.getIncomeDao();

		IncomeBean bean = new IncomeBean();
		bean.setName("Test");
		bean.setCost(1974);
		dao.create(bean);

		Application.log("ha", dao.getAll().toString());
		*/
		
		

		btnList = (Button) findViewById(R.id.btnList);
		btnTable = (Button) findViewById(R.id.btnTable);
		
		btnList.setOnClickListener(this);
		btnTable.setOnClickListener(this);
		


	}
	
	public void onClick(View v) {
		if(btnList.equals(v)){
			Intent intent = new Intent(this, IncomeManagerController.class);
			startActivity(intent);	
			
		}else if(btnTable.equals(v)){
			 Application.GetInstance().getDataBaseHelper().deleteAllTables();
			 Application.GetInstance().getDataBaseHelper().createAllTables();
		}

		

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}
}
